#pragma once

#include "XmlppForward.hpp"
#include <glibmm/ustring.h>

namespace BuildNG
{
  class SettingsFile;

  class Settings
  {
  public:
    static void init(const Glib::ustring &settings_file);
    static void shutdown();

    static Glib::ustring                get_setting_string(const Glib::ustring &xpath);
    static bool                         try_get_setting_string(const Glib::ustring &xpath,Glib::ustring &res);

    /// returns the path as an absolute path. If it's a relative path, it will 
    /// be resolved, relative to the file the setting was defined in.
    static Glib::ustring                get_setting_path(const Glib::ustring &xpath);
    static std::vector<Glib::ustring>   get_setting_strarr(const Glib::ustring &xpath);

  private:
    static SettingsFile *global_settings_file;
  };

  class SettingsFile
  {
  public:
    SettingsFile(const Glib::ustring &file_name);
    ~SettingsFile();

    Glib::ustring               get_setting_string(const Glib::ustring &xpath);
    bool                        try_get_setting_string(const Glib::ustring &xpath,Glib::ustring &res);
    /// returns the path as an absolute path. If it's a relative path, it will 
    /// be resolved, relative to the file the setting was defined in.
    Glib::ustring               get_setting_path(const Glib::ustring &xpath);
    std::vector<Glib::ustring>  get_setting_strarr(const Glib::ustring &xpath);
    bool                        try_get_setting_strarr(const Glib::ustring &xpath,std::vector<Glib::ustring> &res);

  private:
    Glib::ustring               settings_file_path;
    Xml::Document*              doc;

    static Glib::ustring        node_to_text(const Xml::Node *node);
    static Glib::ustring        element_content_to_text(const Xml::Element &element);
  };
}
